package com.cy.myblog.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 处理匹配smtp
 * Created by Administrator on 2015/6/18.
 */
public class SMTPUtil {
    public static String autoMailServer(String username){
        return "smtp." + getHost(username);
    }

    public static String getHost(String username){
        return username.split("@")[1];
    }

    public static String getSMTPAddress(String username){
        String smtpAddress = null;
        Properties props = new Properties();
        try{
            InputStream in = SMTPUtil.class.getResourceAsStream("/smtp.properties");
            props.load(in);
            smtpAddress = props.getProperty(getHost(username).trim());
            if(smtpAddress == null)
                smtpAddress = autoMailServer(username);
        }catch(IOException ex){
            ex.printStackTrace();
        }

        return smtpAddress;
    }
}
